﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class LocationConfig : POBaseConfig<LocationPO>
    {
        public override void InitializeData(EntityTypeBuilder<LocationPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<LocationPO> builder, ref int index)
        {
            builder.HasComment("货位表");
            builder.Property(entity => entity.Code).ConfigColumn("CODE", "编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.LineCode).ConfigColumn("LINE_CODE", "产线编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.ZoneCode).ConfigColumn("ZONE_CODE", "区域编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.EquipmentCode).ConfigColumn("EQUIPMENT_CODE", "设备编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TypeCode).ConfigColumn("TYPE_CODE", "类型编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Line).ConfigColumn("LINE", "行").HasColumnOrder(index++);
            builder.Property(entity => entity.Column).ConfigColumn("COLUMN", "列").HasColumnOrder(index++);
            builder.Property(entity => entity.Layer).ConfigColumn("LAYER", "层").HasColumnOrder(index++);
            builder.Property(entity => entity.Depth).ConfigColumn("DEPTH", "深").HasColumnOrder(index++);
            builder.Property(entity => entity.Length).ConfigColumn("LENGTH", "长").HasColumnOrder(index++);
            builder.Property(entity => entity.Width).ConfigColumn("WIDTH", "宽").HasColumnOrder(index++);
            builder.Property(entity => entity.Height).ConfigColumn("HEIGHT", "高").HasColumnOrder(index++);
            builder.Property(entity => entity.StateCode).ConfigColumn("STATE_CODE", "状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.UseStateCode).ConfigColumn("USE_STATE_CODE", "使用状态编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierCode).ConfigColumn("SUPPLIER_CODE", "供应商编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierServerCode).ConfigColumn("SUPPLIER_SERVER_CODE", "供应商服务编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierEquipmentCode).ConfigColumn("SUPPLIER_EQUIPMENT_CODE", "供应商设备编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierStateCode).ConfigColumn("SUPPLIER_STATE_CODE", "供应商状态编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.SupplierModeCode).ConfigColumn("SUPPLIER_MODE_CODE", "供应商模式编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.Temperature).ConfigColumn("TEMPERATURE", "温度", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.ContainerBarcode).ConfigColumn("CONTAINER_BARCODE", "容器条码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TrayBarcode1).ConfigColumn("TRAY_BARCODE_1", "底层托盘条码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TrayBarcode2).ConfigColumn("TRAY_BARCODE_2", "中层托盘条码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TrayBarcode3).ConfigColumn("TRAY_BARCODE_3", "上层托盘条码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TotalCellCount).ConfigColumn("TOTAL_CELL_COUNT", "托盘组电池数量").HasColumnOrder(index++);
            builder.Property(entity => entity.MaterialCode).ConfigColumn("MATERIAL_CODE", "物料编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyRouteCode).ConfigColumn("TECHNOLOGY_ROUTE_CODE", "工艺路径编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyProcessCode).ConfigColumn("TECHNOLOGY_PROCESS_CODE", "工艺工序编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.OutboundTargetStation).ConfigColumn("OUTBOUND_TARGET_STATION", "出库目标站台", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyAgingTime).ConfigColumn("TECHNOLOGY_AGING_TIME", "工艺静置时间", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.ActualAgingTime).ConfigColumn("ACTUAL_AGING_TIME", "实际静置时间").HasColumnOrder(index++);
            builder.Property(entity => entity.InboundTime).ConfigColumn("INBOUND_TIME", "入库时间").HasColumnOrder(index++);
            builder.Property(entity => entity.OutStateCode).ConfigColumn("OUT_STATE_CODE", "出库状态编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.LastOutboundTime).ConfigColumn("LAST_OUTBOUND_TIME", "最后出库时间").HasColumnOrder(index++);
            builder.Property(entity => entity.Message).ConfigColumn("MESSAGE", "消息", 2000).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<LocationPO> builder)
        {
            builder.HasIndex(entity => new { entity.Code, entity.WarehouseCode, entity.LineCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();

            builder.HasIndex(entity => new
            {
                entity.ZoneCode,
                entity.Line,
                entity.Column,
                entity.Layer,
                entity.Depth,
                entity.WarehouseCode,
                entity.LineCode
            }).HasDatabaseName($"UN_{TableName}_2").IsUnique();

            builder.HasIndex(entity => new
            {
                entity.ZoneCode,
                entity.EquipmentCode,
                entity.TypeCode,
                entity.StateCode,
                entity.UseStateCode,
                entity.SupplierModeCode,
                entity.SupplierStateCode
            }).HasDatabaseName($"IDX_{TableName}_1");
        }
    }
}
